﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DbAdapter.sqldbAdapter;

namespace Water.Model
{
    public class ExplosionAccidentDetail : Pipeline
    {
        public string MRNO { get; set; }
        public DateTime PipeBzDt { get; set; }
        public string BzAddress { get; set; }
        public double Temperature { get; set; }
        public string ValveQk { get; set; }
        public double AreaShuiYa { get; set; }
        public string MadeUnit { get; set; }
        public DateTime MadeDt { get; set; }
        public string MadeFsh { get; set; }
        public string JkTianliao { get; set; }
        public string FangfuCl { get; set; }
        public int BzCount { get; set; }
        public string RoadType { get; set; }
        public string RoadSoil { get; set; }
        public string RoadUpEnvir { get; set; }
        public string JiaoTongFh { get; set; }
        public double DxiaShuiW { get; set; }
        public double PHValue { get; set; }
        public DateTime XfDT { get; set; }
        public string WorkUnit { get; set; }
        public string UserMans { get; set; }
        public string NearQk { get; set; }
        public string LossInfo { get; set; }
        public double LossWater { get; set; }
        public string BzReason { get; set; }
        public string YingXiangFw { get; set; }
        public string Image1Url { get; set; }
        public string Image2Url { get; set; }
        public string OperateEmp { get; set; }
        public DateTime CreateDt { get; set; }

        public ExplosionAccidentDetail GetExplosionAccidentDetail(string mrno)
        {
            string sql = "SELECT a.MRNO,a.PipeBzDt,a.BzAddress,a.Temperature,a.ValveQk,a.AreaShuiYa,a.MadeUnit,a.MadeDt,"
                + "a.MadeFsh,a.JkTianliao,a.FangfuCl,a.BzCount,a.RoadType,a.RoadSoil,a.RoadUpEnvir,a.JiaoTongFh,"
                + "a.DxiaShuiW,a.PHValue,a.XfDT,a.WorkUnit,a.UserMans,a.NearQk,a.LossInfo,a.LossWater,a.BzReason,"
                + "a.YingXiangFw,a.Image1Url,a.Image2Url,c.PIPE_D,c.ST_NAME,c.INS_DATE,c.DEPTH "
                + "FROM Tbt_ExplosionAccidentDetail a inner join Tbt_ExplosionAccident b on a.MRNO = b.MRNO inner join TZ_GXSX c on b.EpcNo = c.EpcNO "
                + "where a.MRNO = '" + mrno + "'";
            sqldb db = new sqldb();
            DataSet ds = db.ExecuteDataset(sqlconn.GetConnStr(), CommandType.Text, sql);
            ExplosionAccidentDetail ead = new ExplosionAccidentDetail();
            if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];
                ead.MRNO = dr["MRNO"].ToString();
                ead.PipeBzDt = Convert.ToDateTime(dr["PipeBzDt"]);
                ead.PIPED = Convert.ToSingle(dr["PIPE_D"]);
                ead.BzAddress = dr["BzAddress"].ToString();
                ead.Temperature = Convert.ToDouble(dr["Temperature"]);
                ead.INSDATE = Convert.ToDateTime(dr["INS_DATE"]);
                ead.DEPTH = Convert.ToSingle(dr["DEPTH"]);
                ead.ValveQk = dr["ValveQk"].ToString();
                ead.AreaShuiYa = Convert.ToDouble(dr["AreaShuiYa"]);
                ead.MadeUnit = dr["MadeUnit"].ToString();
                ead.MadeDt = Convert.ToDateTime(dr["MadeDt"]);
                ead.MadeFsh = dr["MadeFsh"].ToString();
                ead.JkTianliao = dr["JkTianliao"].ToString();
                ead.FangfuCl = dr["FangfuCl"].ToString();
                ead.BzCount = Convert.ToInt32(dr["BzCount"]);
                ead.RoadType = dr["RoadType"].ToString();
                ead.RoadSoil = dr["RoadSoil"].ToString();
                ead.RoadUpEnvir = dr["RoadUpEnvir"].ToString();
                ead.JiaoTongFh = dr["JiaoTongFh"].ToString();
                ead.DxiaShuiW = Convert.ToDouble(dr["DxiaShuiW"]);
                ead.PHValue = Convert.ToDouble(dr["PHValue"]);
                ead.XfDT = Convert.ToDateTime(dr["XfDT"]);
                ead.WorkUnit = dr["WorkUnit"].ToString();
                ead.UserMans = dr["UserMans"].ToString();
                ead.NearQk = dr["NearQk"].ToString();
                ead.LossInfo = dr["LossInfo"].ToString();
                ead.LossWater = Convert.ToDouble(dr["LossWater"]);
                ead.BzReason = dr["BzReason"].ToString();
                ead.YingXiangFw = dr["YingXiangFw"].ToString();
                ead.Image1Url = dr["Image1Url"].ToString();
                ead.Image2Url = dr["Image2Url"].ToString();
                //ead.OperateEmp = dr["OperateEmp"].ToString();
                //ead.CreateDt = Convert.ToDateTime(dr["CreateDt"]);
            }
            return ead;
        }

        public int UpdateExplosionAccidentDetail(ExplosionAccidentDetail pead)
        {
            string sql = "Update Tbt_ExplosionAccidentDetail " +
                         "set PipeBzDt = '" + pead.PipeBzDt + "'," +
                         "BzAddress = '" + pead.BzAddress + "'," +
                         "Temperature = " + pead.Temperature.ToString() + "," +
                         "ValveQk = '" + pead.ValveQk + "'," +
                         "AreaShuiYa = " + pead.AreaShuiYa.ToString() + "," +
                         "MadeUnit = '" + pead.MadeUnit + "'," +
                         "MadeDt = '" + pead.MadeDt + "'," +
                         "MadeFsh = '" + pead.MadeFsh + "'," +
                         "JkTianliao = '" + pead.JkTianliao + "'," +
                         "FangfuCl = '" + pead.FangfuCl + "'," +
                         "BzCount = " + pead.BzCount.ToString() + "," +
                         "RoadType = '" + pead.RoadType + "'," +
                         "RoadSoil = '" + pead.RoadSoil + "'," +
                         "RoadUpEnvir = '" + pead.RoadUpEnvir + "'," +
                         "JiaoTongFh = '" + pead.JiaoTongFh + "'," +
                         "DxiaShuiW = " + pead.DxiaShuiW + "," +
                         "PHValue = " + pead.PHValue.ToString() + "," +
                         "XfDT = '" + pead.XfDT + "'," +
                         "WorkUnit = '" + pead.WorkUnit + "'," +
                         "UserMans = '" + pead.UserMans + "'," +
                         "NearQk = '" + pead.NearQk + "'," +
                         "LossInfo = '" + pead.LossInfo + "'," +
                         "LossWater = " + pead.LossWater.ToString() + "," +
                         "BzReason = '" + pead.BzReason + "'," +
                         "YingXiangFw = '" + pead.YingXiangFw + "'," +
                         "Image1Url = '" + pead.Image1Url + "'," +
                         "Image2Url = '" + pead.Image2Url + "' where MRNO = '" + pead.MRNO + "'";
            sqldb db = new sqldb();
            return db.ExecuteNonQuery(sqlconn.GetConnStr(), CommandType.Text, sql);
        }
    }
}
